<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
    <link rel="stylesheet" th:href="@{/ajax/bootstrap-table/bootstrap-table.min.css?v=20200727}"/>
    <script th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script th:src="@{/ajax/bootstrap-table/bootstrap-table.min.js?v=20200727}"></script>
    <script th:src="@{/ajax/bootstrap-table/locale/bootstrap-table-zh-CN.min.js?v=20200727}"></script>
    <script th:src="@{/ajax/bootstrap-table/extensions/mobile/bootstrap-table-mobile.js?v=20200727}"></script>

</head>
<body class="gray-bg">
<div class="panel-body" style="padding-bottom:0px;">
    <div class="btn-group" id="toolbar">
        <button class="btn btn-default" id="btn_add" onclick='genCode()' type="button">
            <span aria-hidden="true" class="glyphicon glyphicon-download-alt"></span>生成
        </button>
    </div>
    <table id="genTable">
    </table>
</div>
<script th:inline="javascript">

    $(function () {
        var $table = $("#genTable");

        $table.bootstrapTable({
            url: "/generator/getTableDatas",
            method: "post",
            // height:'600px',
            search: 'true',
            strictSearch: true,
            toolbar: '#toolbar',
            striped: true,                      //是否显示行间隔色
            cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: 'true',
            pageNumber: '1',
            pageSize: '10',
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            strictSearch: true, //是否显示刷新
            showColumns: true, //是否显示所有的列
            showRefresh: true, //是否显示刷新按钮
            showToggle:true, //是否显示详细视图和列表视图的切换按钮
            cardView: false, //是否显示详细视图
            fixedColumns: true,//固定列
            fixedNumber:2,//固定前两列
            sidePagination: 'server', // 设置为服务器端分页server  client前台分页

            queryParams:function(param){
                return {
                    offset: param.offset,     //这四个是默认传输的值
                    limit: param.limit,
                    sort: param.sort,
                    order:param.order
                }
            },
            columns: [
                {
                    field: 'select',
                    checkbox: true,
                    align: "center",
                    valign: 'middle'
                },
                {
                    field:'',
                    title: '编号',
                    align: "center",
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }

                },
                {
                    field: 'tableName',
                    title: '表名',
                    align: "center",
                    valign: 'middle'
                },
                {
                    field: 'tableComment',
                    title: '备注',
                    align: "center",
                    valign: 'middle',
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    align: "center",
                    valign: 'middle'
                }

            ],

        });

    });


    function genCode() {
        var tableNames = [];
        var data = $('#genTable').bootstrapTable('getSelections');
        if (data.length > 0) {
            if (confirm('你确定要生成的数据文件吗？')) ;
            for (var i = 0; i < data.length; i++) {
                tableNames[i] = data[i].tableName;
            }
            console.info(data)

            window.location.href = "/generator/code?tableNames=" + tableNames.toString();

        } else {
            alert("请选择数据")
        }
    };
</script>
</body>
</html>